package com.ruoyi.system.task;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ruoyi.common.core.domain.entity.SysProject;
import com.ruoyi.system.domain.SysMaintain;
import com.ruoyi.system.service.ISysAdminProjectService;
import com.ruoyi.system.service.ISysMaintainService;
import com.ruoyi.system.service.ITDeviceMaintainService;
import com.ruoyi.system.service.ITProdRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 设备维护信息定时任务处理
 * 定时统计新增各项目是否有待处理维护任务
 */
@Component
@EnableScheduling
public class MaintainTask {
    @Autowired
    private ISysMaintainService sysMaintainService;
    @Autowired
    private ISysAdminProjectService sysAdminProjectService;
    @Autowired
    private ITProdRecordService prodRecordService;
    @Autowired
    private ITDeviceMaintainService projectMaintainService;

//    @Scheduled(cron = "1/1 * * * * ?")
    public void execute() {
        List<SysMaintain> sysMaintainList = sysMaintainService.list();
        List<SysProject> projectList = sysAdminProjectService.list(new LambdaQueryWrapper<SysProject>()
                .eq(SysProject::getStatus,0));
        projectList.forEach(item -> {
            //有产量之后的项目才进行维护
            int finishNum = prodRecordService.sumRecord(item.getId());
            if(finishNum > 0) {
                sysMaintainList.forEach(sysMaintain -> {
                    //查询上一次执行时间，如无记录取第一次产品生产时间

                });
            }
        });
    }

}
